from django.db import models
from django.contrib.auth.models import User

class CarRank(models.Model):
    series_id = models.IntegerField(primary_key=True, verbose_name='车系ID')
    series_name = models.CharField(max_length=100, null=True, blank=True, verbose_name='车系名称')
    image = models.TextField(null=True, blank=True, verbose_name='车型展示图URL')
    ranks = models.IntegerField(null=True, blank=True, verbose_name='当前排名')
    min_price = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name='最低指导价（万元）')
    max_price = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name='最高指导价（万元）')
    last_rank = models.IntegerField(null=True, blank=True, verbose_name='上月排名')
    count = models.IntegerField(null=True, blank=True, verbose_name='月销量（台）')
    score = models.FloatField(null=True, blank=True, verbose_name='综合评分')
    car_review_count = models.IntegerField(null=True, blank=True, verbose_name='用户点评数量')
    show_trend = models.BooleanField(null=True, blank=True, verbose_name='是否显示排名趋势图标')
    descender_price = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True, verbose_name='降价幅度（万元）')
    series_pic_count = models.IntegerField(null=True, blank=True, verbose_name='车系图片数量')
    brand_id = models.IntegerField(null=True, blank=True, verbose_name='品牌ID')
    brand_name = models.CharField(max_length=50, null=True, blank=True, verbose_name='品牌名称')
    sub_brand_id = models.IntegerField(null=True, blank=True, verbose_name='子品牌ID')
    sub_brand_name = models.CharField(max_length=50, null=True, blank=True, verbose_name='子品牌名称')
    price = models.CharField(max_length=50, null=True, blank=True, verbose_name='价格区间')
    dealer_price = models.CharField(max_length=50, null=True, blank=True, verbose_name='经销商参考价格')
    has_dealer_price = models.BooleanField(null=True, blank=True, verbose_name='是否有经销商参考价')
    
    class Meta:
        db_table = 'car_rank'
        verbose_name = '汽车排行榜'
        verbose_name_plural = verbose_name
    
    def __str__(self):
        return self.series_name or '未命名车系'

class UserProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
    phone = models.CharField(max_length=20, blank=True, null=True, verbose_name='电话号码')
    avatar = models.ImageField(upload_to='avatars/', blank=True, null=True, verbose_name='头像')
    
    class Meta:
        verbose_name = '用户信息'
        verbose_name_plural = verbose_name
    
    def __str__(self):
        return self.user.username
